var express = require('express');
var router = express.Router();
const goodsController = require('../controllers/student_controller');
const  cart =require('../models/student_bean')

//增加学生信息
router.post('/add', function (req, res) {
    console.log(req.body.values);
    goodsController.addcart(new cart.carts(req.body.values),(ret) =>res.json(ret)
    ,
    (err) => res.json(err)
    )
})

//查询数据
router.post('/selectcart', function (req, res) {
    console.log(req.body.page,req.body.size);
    goodsController.getcart(new cart.select(req.body.page,req.body.size),(ret) =>res.json(ret)
    ,
        (err) => res.json(err)
    )
})


router.get('/selectall', function (req, res) {
    console.log(req.body.page,req.body.size);
    goodsController.getall(null,(ret) =>res.json(ret)
    ,
        (err) => res.json(err)
    )
})


router.get('/legend', function (req, res) {
    console.log(req.body.page,req.body.size);
    goodsController.getlegend(null,(ret) =>res.json(ret)
    ,
        (err) => res.json(err)
    )
})
// 查询单条数据
router.post('/select', function (req, res) {
    goodsController.getlist(new cart.list(req.body.field,req.body.input),(ret) =>res.json(ret)
    ,
        (err) => res.json(err)
    )
})


//删除数据
router.delete('/delete', function (req, res) {
    console.log(req.body.userid,req.body.qty);
   goodsController.deletecart(new cart.deltete(req.body.userid),(ret) =>res.json(ret)
    ,
       (err) => res.json(err)
   )
})


//修改数据
router.put('/updata', function (req, res) {
    goodsController.updatecart(req.body.data,(ret) =>res.json(ret)
    ,
        (err) => res.json(err)
    )
})


module.exports =router